"""
获取视频的原播放量（当前播放量）
"""
import re
from time import sleep

import requests


def get_video_view_counts(url):
    for i in range(5):
        try:
            res = requests.get(
                url,
                headers={
                    # "Host": "www.yangshipin.cn",
                    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:126.0) Gecko/20100101 Firefox/126.0",
                    # "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8",
                    # "Accept-Language": "zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2",
                    # "Accept-Encoding": "gzip, deflate, br, zstd",
                    "Referer": "https://www.yangshipin.cn/",
                    # "DNT": "1",
                    # "Sec-GPC": "1",
                    # "Connection": "keep-alive",
                    "Cookie": "ysp_uv=1; guid=lxb88r2y_aldsiv0hfol; versionName=99.99.99; versionCode=999999; vplatform=109; platformVersion=Firefox; deviceModel=126; newLogin=1; updateProtocol=1; nseqId=8; nrequest-id=999999Nv4GtmP3lU1718163090526",
                    # "Upgrade-Insecure-Requests": "1",
                    # "Sec-Fetch-Dest": "document",
                    # "Sec-Fetch-Mode": "navigate",
                    # "Sec-Fetch-Site": "same-origin",
                    # "Sec-Fetch-User": "?1",
                    # "If-Modified-Since": "Fri, 07 Jun 2024 12:58:17 GMT",
                    # "If-None-Match": "25cb975e08d7961b0d0b8083af2e9066",
                    # "Priority": "u=1",
                })
            match_obj = re.findall(r'"subtitle":"(.+)次观看"', res.text)
            if not match_obj:
                return True, 0
            return True, match_obj[0]
        except Exception as e:
            sleep(1)
    return False, 0

if __name__ == '__main__':
    url = 'https://www.yangshipin.cn/video/home?vid=d0000283e0h'
    count = get_video_view_counts(url)
    print(count)
